//
//  ListOfVCell.m
//  NewMyMusicAPP
//
//  Created by 11_wyq on 15/6/26.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "ListOfVCell.h"

@implementation ListOfVCell

-(void)dealloc
{
    [_number release];
    [_title release];
    [_artistName release];
    [_score release];
    [_myImageView release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubview];
    }
    return self;
    
}


-(void)createSubview
{
    
    self.myImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, MYWIDTH, 200 * HEIGHT)];
    [self.contentView addSubview:_myImageView];
    self.myImageView.backgroundColor = [UIColor lightGrayColor];
    [_myImageView release];

    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, MYWIDTH, 200 * HEIGHT)];
    view.backgroundColor = [UIColor blackColor];
    view.alpha = 0.15;
    [_myImageView addSubview:view];
    [view release];
    
    //标题
    self.title = [[UILabel alloc]initWithFrame:CGRectMake(120 * WIDTH, 130 * HEIGHT, 230 * WIDTH, 30 * HEIGHT)];
    _title.text = @"标题";
    _title.textAlignment = UITextAlignmentRight;//右对齐
    [_title setFont:[UIFont fontWithName:@"Helvetica-Bold" size:15]];//加粗字体
    _title.textColor = [UIColor whiteColor];
    [_myImageView addSubview:_title];
    [_title release];
    //作者
    self.artistName = [[UILabel alloc]initWithFrame:CGRectMake(250 * WIDTH, 155 * HEIGHT, 110 * WIDTH, 30 * HEIGHT)];
    _artistName.textAlignment = UITextAlignmentRight;//右对齐
    _artistName.text = @"作者";
    [_artistName setFont:[UIFont fontWithName:@"Helvetica-Bold" size:15]];//加粗字体
    [_myImageView addSubview:_artistName];
    [_artistName release];
    _artistName.textColor = [UIColor colorWithHexString:@"FF9966"];
    
    //排名
    self.number = [[UILabel alloc]initWithFrame:CGRectMake(50 * WIDTH, 70 * HEIGHT, 100 * WIDTH, 100 * HEIGHT)];
    self.number.text = @"1";
    _number.textColor = [UIColor whiteColor];
    [_number setFont:[UIFont fontWithName:@"Helvetica-Bold" size:35]];//加粗字体
    [_myImageView addSubview:_number];
    [_number release];
    
    
    //分数
    self.score = [[UILabel alloc]initWithFrame:CGRectMake(45 * WIDTH , 135 * HEIGHT, 100 * WIDTH, 40 * HEIGHT)];
    _score.textColor = [UIColor whiteColor];
    _score.text = @"99.00";
    [_myImageView addSubview:_score];
    [_score release];
    [_score setFont:[UIFont fontWithName:@"Helvetica-Bold" size:20]];//加粗字体
    
    
    
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.frame = CGRectMake(330, 30, 27, 25);
    [self.contentView addSubview:self.button];
    [_button setBackgroundImage:[UIImage imageNamed:@"zan.png"] forState:UIControlStateNormal];
    [_button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    
    
    _isCollection = NO;
    
    
}



-(void)buttonAction
{
    
    if (!_isCollection) {
        _isCollection = YES;
         [_button setBackgroundImage:[UIImage imageNamed:@"circlelist_heartup@2x.png"] forState:UIControlStateNormal];
        [[DataHandle shareHandleController]openDB];
        [[DataHandle shareHandleController]createCollectTable];
        CollectModel *model = [[CollectModel alloc]init];
        model.title = _model.title;
        model.modelId = _model.myId;
        model.type = @"VIDEO";
        [[DataHandle shareHandleController]insertCollect:model];
        [model release];
        
        
        
    }else
    {
        _isCollection = NO;
        [_button setBackgroundImage:[UIImage imageNamed:@"circlelist_heart@2x.png"] forState:UIControlStateNormal];
        [[DataHandle shareHandleController]openDB];
        [[DataHandle shareHandleController]deleteTable:_model.myId];
        

    }
    
    
    
}





-(void)setModel:(ListOfVModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    NSURL *url = [NSURL URLWithString:_model.albumImg];
    [_myImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"default_discover_moment@3x.png"]];
    _title.text = _model.title;
    _score.text = _model.score;
    _artistName.text = _model.artistName;
    _number.text = _model.number;

    if (!_isCollection) {
         [_button setBackgroundImage:[UIImage imageNamed:@"circlelist_heart@2x.png"] forState:UIControlStateNormal];
    }else{
     [_button setBackgroundImage:[UIImage imageNamed:@"circlelist_heartup@2x.png"] forState:UIControlStateNormal];
    }
}






- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
